package hot100;

public class isPalindrome {
    public boolean isPalindrome(mergeKLists.ListNode head) {
        mergeKLists.ListNode slow = head;
        mergeKLists.ListNode fast = head;
        //快慢指针,slow-> 1/2
        while(fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
        }
        //反转slow - end
        mergeKLists.ListNode curN = null;
        mergeKLists.ListNode cur = slow.next;
        slow.next = null;
        while(cur != null) {
            curN = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curN;
        }
        //比较head md
        while(slow != null) {
            if(head.val != slow.val) {
                return false;
            }
            head = head.next;
            slow = slow.next;
        }
        return true;
    }
}
